<!--
 * @Author: HeAo
 * @Date: 2021-09-29 11:15:41
 * @LastEditTime: 2021-09-29 11:26:22
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2103code\3-1-ES6\day05\6-generator-ajax.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./jquery.js"></script>
  <script>
    const baseURL = 'http://47.94.46.113:8888'

    function getAjax() {
      return $.ajax({
        url: baseURL + '/index/category/findAll',
        method: 'get',
        success(res) {
          iterator.next(res)
        }
      })
    }

    // 第一个状态的出口数据，作为下一个状态的入口数据
    // 这个数据是第二次调用.next()传递的实参
    function* myGenFun() {
      let result = yield getAjax()

      console.log('处理数据', result);
      yield '结束'
    }

    let iterator = myGenFun()
    iterator.next()
  </script>
</head>

<body>

</body>

</html>